/*
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */

package bgtp;

import java.util.*;
import java.lang.*;
import java.io.IOException;


/**
 *класс занимается приемом новых сообщений и больше ничего
 */
public class Acceptor extends Thread
{
    private String		host;
    private String		port;
    private Registrator		register;
    private TCPTransport	tcp;

    /**
     *конструяктор
     *@param host_ хостнейм на котором поднимать сервер
     *@param port_ порт который слушать бкдем на предмет соединения
     *@param reg  экземпляр ркгистратора. т.к. сам кацептор только соединения принимает
     */
    public Acceptor(String host_, String port_, Registrator reg)
    {
	register  = reg;
	host	  = host_;
	port	  = port_;
	tcp	  = new TCPTransport(host, port);
    }


    public void run()
    {
	TCPTransport.TCPServer	clt = null;
	try
	    { 
		clt = tcp.getServer();

		while(true)
		    {
			register.newAdept(new OverHTTP(clt.getConnection()));
		    }
	    }
	catch(IOException ioe)
	    {
		ioe.printStackTrace();
		return;
	    }
    }
}